<?php
namespace Wx\Controller;
use Think\Controller;
class CommonController extends Controller {
    // 初始化方法
    public function _initialize(){
		//dump(session()); 
		//用户未登录
		$member=D('member');
		$store = D("shop_store");
		
		//浏览器测试用-传递openid进行登录
		//dump($_GET['openid']);
		if($_GET['openid']){
			$getone=$member->where("`openid` LIKE '".$_GET['openid']."'")->find();
			if($getone){
				$store_info = $store->where("status != 0 AND u_id= {$getone['id']}")->find();
				//设置登录信息
				session('u_id',$getone['id']);  //设置session——用户id
				session('nickname',$getone['nickname']);  //设置session——用户id
				session('s_id',$store_info['id']);  //设置session——用户店铺id
				session('openid',$_GET['openid']);  //设置session——微信openid
				session('u_type',$getone['u_type']);  //设置session——用户类型
				session('focus',$getone['focus']);  //设置session——关注状态 1已关注 0未关注

			}
		}//end if
		//浏览器测试用-end
			
		
		//微信授权获取openid进行登录
		if( empty(session('u_id')) ){
			//获取openid
			//获取当前网页，授权后跳回
			$path =  $_SERVER['REQUEST_URI'];
			//跳转到微信授权
			redirect('/Wx/Auth/index?path='.$path);
		}//end if
		//检测是否关注
		$sc=new \Wx\Controller\AuthnoticeController();  //用绝对路径找
		$sc->checkFocus();
    }//end fun

}//end class